
#include "gtest/gtest.h"
#include "entitymanager.h"
#include "Entities/dummy.h"
#include "Skills/typeAttack.h"
#include "Skills/link.h"
#include <memory>
#include <Entities/plant.h>
using namespace std;

TEST(plant_attack_test, bombing_test)
{
    unique_ptr<Game> g(new Game());
    Actor* attacker = g->entityManager.get<entity::TestPlant>();
    Actor* attacker2 = g->entityManager.get<entity::TestPlant>();
    Actor* attacker3 = g->entityManager.get<entity::TestPlant>();
    int max_hp = stoi(attacker->properties["max_hp"]);
    attacker->properties["attack"] = to_string(10);
    skill::Bombing* bombing;
    attacker->learnSkill(bombing = new skill::Bombing);
    attacker->setPos({0, 0});
    attacker2->setPos({0, int(floor(sqrt(BombingRadius)))});
    attacker3->setPos({0, int(floor(sqrt(BombingRadius))) + 1});
    g->setupBattleGround();

    attacker->useLater("Bombing", {to_string(0), to_string(0)});
    g->oneRoundRun();
    EXPECT_EQ(attacker->properties["hp"], to_string(max_hp - int(10 * BombingDamage)));
    EXPECT_EQ(attacker2->properties["hp"], to_string(max_hp - int(10 * BombingDamage)));
    EXPECT_EQ(attacker3->properties["hp"], to_string(max_hp));
    g->dumpReplay("bombing");
}

TEST(plant_attack_test, hurtbuff_test)
{
    unique_ptr<Game> g(new Game());
    Entity* victim = g->entityManager.get<entity::TestPlant>();
    skill::HurtBuff* hurtBuff = new skill::HurtBuff(10, 1, 2);
    victim->learnSkill(hurtBuff);
    g->setupBattleGround();

    int max_hp = stoi(victim->properties["max_hp"]);
    g->oneRoundRun();
    EXPECT_EQ(victim->properties["hp"], to_string(max_hp - 10));
    g->oneRoundRun();
    EXPECT_EQ(victim->properties["hp"], to_string(max_hp - 10 * 2));
    g->oneRoundRun();
    EXPECT_EQ(victim->properties["hp"], to_string(max_hp - 10 * 2));
    g->dumpReplay("hurtBuff");
}

TEST(plant_attack_test, scourgebuff_test)
{
    //not supported currently.
}